CC := gcc
MKDIR := mkdir
RM := rm -fr

DIR_OF_OBJS := objs
DIR_OF_TARGET := target

DIRS := $(DIR_OF_OBJS) $(DIR_OF_TARGET)

TARGET := $(DIR_OF_TARGET)/hello-makefile.out
SRCS := $(wildcard *.c) # main.c const.c func.c
OBJS := $(SRCS:.c=.o) # main.o const.o func.o
OBJS := $(addprefix $(DIR_OF_OBJS)/, $(OBJS)) # objs/main.o objs/const.o objs/func.o

.PHONY : rebuild clean all

$(TARGET): $(DIRS) $(OBJS)
	$(CC) -o $@ $(OBJS)
	@echo "Target File ==> $@"

$(DIRS):
	$(MKDIR) $@

$(DIR_OF_OBJS)/%.o: %.c
    ifeq ($(DEBUG),true)
		$(CC) -o $@ -g -c $^
    else
		$(CC) -o $@ -c $^
    endif

rebuild: clean all

all: $(TARGET)

clean:
	$(RM) $(DIRS)
